<template>
  <a-modal
    :visible="visible"
    class="large-modal"
    @cancel="$emit('update:visible', false)"
  >
    <template slot="footer">
      <a-button @click="$emit('update:visible', false)">
        关闭
      </a-button>
    </template>
    <div v-loading="loading">
      <a-tabs
        type="card"
        :active-key="activeKey"
        @change="tabChange"
      >
        <a-tab-pane
          key="3"
          tab="合同评审（公司）"
        />
        <a-tab-pane
          key="4"
          tab="授权申请"
        />
        <a-tab-pane
          key="5"
          tab="用印申请"
        />
        <a-tab-pane
          key="6"
          tab="成本分析表"
        />
        <a-tab-pane
          key="7"
          tab="资金策划表"
        />
        <a-tab-pane
          key="8"
          tab="重大风险化解措施"
        />
        <a-tab-pane
          key="1"
          tab="基本信息变更"
        />
      </a-tabs>
      <a-table
        :columns="columns"
        :data-source="tableData"
      >
        <span
          slot="num"
          slot-scope="text, record, index"
        >{{ index + 1 }}</span>
        <template
          slot="createTime"
          slot-scope="text, record"
        >
          {{ record.createTime | dateFormat }}
        </template>
        <div
          slot="operation"
          slot-scope="text, record"
        >
          <span @click="$emit('approval', { record, activeKey })">审批意见</span>
          <span @click="handleEdit(record)">查看详情</span>
        </div>
      </a-table>
    </div>
  </a-modal>
</template>

<script>
import totalPackageContractApi from '@/api/legal/branchContract/totalPackageContract'

export default {
  name:'a'+Date.now(),
  props: {
        id: {
            type: [String, Number],
            default: ''
        },
        visible: {
            type: Boolean,
            default: false
        }
    },
    data() {
        return {
            activeKey: '3',
            loading: false,
            columns: [
                {
                    title: '序号',
                    scopedSlots: { customRender: 'num' }
                },
                {
                    title: '创建人',
                    dataIndex: 'creatorName'
                },
                {
                    title: '创建时间',
                    dataIndex: 'createTime',
                    scopedSlots: { customRender: 'createTime' }
                },
                {
                    title: '操作',
                    dataIndex: 'operation',
                    scopedSlots: { customRender: 'operation' }
                }
            ],
            tableData: []
        }
    },
    watch: {
        async visible(val) {
            if (val) {
                this.loading = true
                let res = await totalPackageContractApi.findListCompanyReviewHistory({}, { id: this.id })
                if (res && res.code === 200) {
                    this.tableData = res.data
                }
                this.loading = false
            } else {
                this.activeKey = '3'
                this.tableData = []
            }
        }
    },
    created() {},
    methods: {
        handleEdit(record = {}) {
            this.$router.push({
                path: '/legal/branch-contract/total-package-contract/detail',
                query: {
                    id: (record && record.baseId) || '',
                    businessId: record && (record.businessId || record.baseBusinessId || record.baseId || ''),
                    state: 3,
                    activeKey: this.activeKey
                }
            })
        },
        async tabChange(key) {
            this.tableData = []
            this.loading = true
            this.activeKey = key
            let res
            switch (key) {
                case '3':
                    res = await totalPackageContractApi.findListCompanyReviewHistory({}, { id: this.id })
                    break
                case '4':
                    res = await totalPackageContractApi.findListApplyForAuthorityHistory({}, { id: this.id })
                    break
                case '5':
                    res = await totalPackageContractApi.findListApplyForSealHistory({}, { id: this.id })
                    break
                case '6':
                    res = await totalPackageContractApi.findListGeneralContractCostAnalysisHistory({}, { id: this.id })
                    break
                case '7':
                    res = await totalPackageContractApi.findListProjectFundPlanTable({}, { id: this.id })
                    break
                case '8':
                    res = await totalPackageContractApi.findListByGeneralContractMajorRisksHistory({}, { id: this.id })
                    break
                case '1':
                    res = await totalPackageContractApi.findListGeneralContractHistory({}, { id: this.id })
                    break
            }
            if (res && res.code === 200) {
                this.tableData = res.data
            }
            this.loading = false
        }
    }
}
</script>

<style scoped>
</style>
